TimeInput = ({
	color: {
		caption: "#A4B9D7"
	},
	splitTimeChar: ":",
	setp: 5,
	hotInput: null,
	clsText:'¹关闭',
	initli: false,
	_objectMap:{},
	init: function() {
		return this.addUI().hide();
	},
	uanv_tool_CE: function(type, parent, className, HTML) {
		var obj = document.createElement(type.toUpperCase());
		className && (obj.className = className);
		HTML && (obj.innerHTML = HTML);
		if(!parent){
			return obj
		}else{
			return parent.appendChild(obj);
		}
	},
	uanv_tool_isIn: function(o, parent) {
		while (o != parent && o != document.body) {
			o = o.parentNode
		};
		return o != document.body;
	},
	onselect: function(d) {
		this.hotInput && (this.hotInput.value = d.h + this.splitTimeChar + d.mi);
	},
	addUI: function() {
		if (this.initli) {
			return;
		}
		this.Win = this.uanv_tool_CE("DIV");
		this.Win.style.background = this.color.caption;
		this.Win.style.position = 'absolute';
		this.Win.style.zIndex = 9999;
		
		var _caption = this.uanv_tool_CE("DIV", this.Win);
		_caption.style.padding = '3px';
		_caption.style.background = this.color.caption;
		_caption.style.overflow = 'hidden';
		
		var selHour = this.uanv_tool_CE("SELECT", _caption);
		var selMinute = this.uanv_tool_CE("SELECT", _caption);
		this.selHour = selHour;
		this.selMinute = selMinute;
		for (var i = 0; i < 24; i++) {
			if(i<10){
				i ='0'+i;
			}
			var tmp = new Option(i, i);
			selHour.options.add(tmp);
		};
		for (var i = 0; i < 60; i=i+TimeInput.setp) {
			v = i;
			if(i<10){
				v ='0'+v;
			}
			var tmp = new Option(v, v);
		    selMinute.options.add(tmp);
		};
		selHour.onchange = selMinute.onchange = function() {
			TimeInput.onselect({h:selHour.value,mi:selMinute.value});
		};
		var cls = this.uanv_tool_CE("SPAN", _caption, false,'x');
		cls.style.cursor="pointer";
		cls.title = this.clsText;
		cls.onclick = function(){
			TimeInput.hide();
		}
		document.onclick = document.body.onclick = function(e) {
			e || (e = window.event);
			var src = e.target || e.srcElement;
			var tmp = src.nodeName.toUpperCase();
			if (tmp == "HTML" || tmp == "BODY") {
				return TimeInput.hide();
			}
			if (src == TimeInput.hotInput || TimeInput.uanv_tool_isIn(src, TimeInput.Win)) {
				return;
			}
			TimeInput.hide();
		};
		document.body.appendChild(this.Win);
		this.initli = true;
		return this;
	},
	timeUp: function(d) {
		if(d){
			d.hou||(d.hou = '0');
			d.min||(d.min = '0');
			tmph = parseInt(d.hou);
			tmpmin = parseInt(d.min);
			if(isNaN(tmph)||tmph<0)tmph = 0;
			if(tmph>23)tmph = 23;
			if(isNaN(tmpmin)||tmpmin<0)tmpmin = 0;
			if(tmpmin>59)tmpmin = 59;
			this.h = tmph;
			this.mi = tmpmin;
			this.selHour.options[this.h].selected = "selected";
			this.selMinute.options[Math.round(this.mi/TimeInput.setp)].selected = "selected";
			if(d.first){
				this.onselect({h:this.selHour.value,mi:this.selMinute.value});
			}
		}
		return this;
	},
	showTo: function(obj) {
		var oldObj = obj;
		for (var pos = {
			x: 0,
			y: 0
		}; obj; obj = obj.offsetParent) {
			pos.x += obj.offsetLeft;
			pos.y += obj.offsetTop
		};
		this.Win.style.left = pos.x + "px";
		this.Win.style.top = (pos.y + 2 + oldObj.offsetHeight) + "px";
		this.Win.style.display = "";
		return this;
	},
	bind: function(input) {
		if (!this.initli) {
			this.init();
		}
		"string" == typeof(input) && (input = document.getElementById(input));
		if (!input.type || input.type.toUpperCase() != "TEXT") {
			return this;
		}
		this.hotInput = input;
		var dates = input.value.split(this.splitTimeChar);
		this.timeUp({hou:dates[0],min:dates[1],first:true});
		this.showTo(this.hotInput = input);
		return this;
	},
	hide: function() {
		this.Win.style.display = "none";
		return this
	}
});